﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Drawing;

using DotSpatial.Topology;

using DotSpatial.Data;

using Point = System.Drawing.Point;

using System.Drawing.Drawing2D;



namespace FXnaGis
{
    [Serializable]
    public class FCircleShape:FShape
    {


        public FCircleShape(string id):this(id,10,new Coordinate(0,0,0))
        { 

        }

        public FCircleShape(string id,double radius,Coordinate center)
            : base(id)
        {
            this._radius = radius;

            this._center = center;

          


        

        }


        double _radius;

        public double Radius
        {
            get { return _radius; }
            set { _radius = value; }
        }


        Coordinate _center;

        public Coordinate Center
        {
            get { return _center; }
            set { _center = value; }
        }

        public override void Move(double xOffset, double yOffset, double zOffset)
        {
            this._center.X += xOffset;
            this._center.Y += yOffset;


        }

        public override bool Intersects(DotSpatial.Topology.Envelope envelope)
        {
            //圆形相交算法，还得自己写，悲剧啊
            //根矩形相交


            LinearRing lr = (LinearRing)envelope.ToLinearRing();
            DotSpatial.Topology . Point pt =new DotSpatial.Topology . Point();
            if (lr.Distance (pt)>this._radius)
            {
                return false;
                
            }
            else
            {
                return true;
            }

           
        }

        public override void Draw(FMapArgs args)
        {
            

            PolyStyle pyStyle = this.Parent.PolyStyle;





            Graphics g = args.Device;

            Point pt = args.ProjToPixel(this._center);



            int length = (int)args.ProjToPixel(this._radius);



            GraphicsPath path = new GraphicsPath();


            path.StartFigure();

            path.AddEllipse(pt.X - length, pt.Y - length, (int)length * 2, length * 2);
          


          
            pyStyle.DrawPath(args.Device, path, 1);

            pyStyle.FillPath(args.Device,path);


            path.Dispose();



           


          


            



        }

        public override Extent Extent
        {
            get
            {
                return new DotSpatial.Data.Extent(this._center.X - Radius, this._center.Y - Radius, this._center.X + this.Radius, this.Center.Y + this.Radius);
            }
        }

   


    }
}
